﻿var app = angular.module('myAPP');
app.controller('ProfileController', function ($scope, $location, $http, $modal) {

    $scope.init = function () {
        $scope.$parent.doselProfile();
        $scope.loadProfile();
        //        $scope.
    };
    $scope.loadProfile = function () {
        $http({
            url: "../../PaydSw.asmx/GetProfileUser",
            dataType: 'json',
            method: 'POST',
            data: '',
            headers: {
                "Content-Type": "application/json"
            }
        }).success(function (response) {
            var data = JSON.parse(response.d);
            
            if (data.Result == 99) {
                $scope.$parent.openAlertLogin(1, "แจ้งเตือน", "คุณไม่สิทธิ์เข้าใช้งาน");
            }
            else if (data.Result == 1) {
                $scope.fullName = data.objUserData.Title + ' ' + data.objUserData.Name;
                $scope.address = data.objUserData.Addr1 + ' ' + data.objUserData.Addr2 + ' ' + data.objUserData.ZipCode;
                //$scope.listPolicy = objDataPolicy;
            }
            else {
                $scope.$parent.openAlertLogin(1, "แจ้งเตือน", "ไม่สามารถค้นหาข้อมูลได้");
            }

        })
        .error(function (error) {
            var dataError = JSON.parse(error.responseText);
            var ErrorMessage = 'error at loadProfile at ProfileController ' + dataError.ExceptionType + ' ' + dataError.Message + ' ' + dataError.StackTrace;
            alert(ErrorMessage);
            $scope.$parent.doselHome();
            $location.path('/home');
        });
    };
});